import requests
import responses_validator
from commons.extract_resp import ext_json
from commons.format_log import step_log

def run_steps(steps):
    """
    解析yaml中步骤信息，根据步骤，执行内容
    :param steps:文件内容
    :return:
    """
    resp = None
    steps = steps['steps']
    for step in steps:
        key = list(step.keys())[0]
        value = list(step.values())[0]
        match key:
            case 'request':
                step_log(key, value)
                resp = requests.request(**value)
            case 'checkpoints':
                step_log(key, value)
                responses_validator.validator(resp ,**value)
            case 'extract':
                step_log(key, value)
                ext = ext_json(resp.json(),value['path'])
                step_log('提取数据：',ext)
                return ext
    return None